< previous page page_24 next page >

Page 24
0024-01.jpg
Figure 2.7.
The LastName field is the primary key field of the Customer table.
Tip.gif
The main role of the primary key is to maintain the internal integrity of a data table. For this reason, no two records in a data table can have the same primary key value. Many companies with large customer bases use Social Security numbers or area codes and telephone numbers, because they know they are likely to have more than one customer with the same name. In these cases, the SSN or phone number would be the primary key field.

A data table can have more than one foreign key. It can also have no foreign key at all. In the Orders Table, the LastName field would be defined as a foreign key field. This means that it is a nonunique field in this data table that points to a key field in an external (foreign) table. Any attempt to add to the Orders table a record that contains a value in the LastName field, which does not also exist in a LastName field in the Customer Table, would result in a database error. For example, if the Customer table contains three records (Smith, Amundsen, and Jones), and you try to add a record to the Orders Table by filling the LastName field of the Orders Table with Paxton, you get a database error. By creating foreign key fields in a table, you build data integrity into your database. This is called referential integrity.
Tip.gif
The main role of a foreign key is to define and maintain relationships between data tables in a database. For this reason, foreign key fields are not unique in the data table in which they exist.

 
< previous page page_24 next page >

If you like this book, buy it!